{% macro action_button(item, action, prefix=None, controller=None, target=None, class='btn-xs'): -%}
    {% if action in ('view', 'edit', 'delete') %}
    <a
    {% set route = uri('{}:{}:{}'.format(prefix, controller, action) if prefix else '{}:{}'.format(controller, action), key=item.key.urlsafe()) if controller else uri(action=action, key=item.key.urlsafe()) %}
    href='{{ route }}'
    class='{{ class }}'
    rel="tooltip"
    title='{{ action }}{{ ' ' + target if target }}'
    {% if action == 'delete' %}
    onclick='javascript: return confirm("Are you sure you want to delete this item?");'
    {% endif %}>
    {% set icon = {'view': 'glyphicon-eye-open', 'edit': 'glyphicon-pencil', 'delete': 'glyphicon-trash'} %}
    <span class="glyphicon {{ icon[action] }}"></span>
    </a>
    {% endif %}
{%- endmacro %}

{% macro add_button(text, tip=None, prefix=None, controller=None): -%}
    <a
    {% set route = uri('{}:{}:add'.format(prefix, controller) if prefix else '{}:add'.format(controller)) if controller else uri(action='add') %}
    href='{{ route }}'
    class='btn btn-sm btn-primary'
    {% if tip %}
        rel="tooltip"
        title='{{ tip }}'
    {% endif %}>
    <i class="glyphicon glyphicon-plus icon-white"></i>
    {{ text }}
    </a>
{%- endmacro %}

{% macro view_edit_delete_buttons(item, controller=None, target=None) -%}
    {{action_button(item, 'view', controller=controller, target=target)}}
    {{action_button(item, 'edit', controller=controller, target=target)}}
    {{action_button(item, 'delete', controller=controller, target=target)}}
{%- endmacro %}

{% macro edit_delete_buttons(item, controller=None, target=None) -%}
    {{action_button(item, 'edit', controller, target=target, class='btn btn-sm btn-primary')}}
    {{action_button(item, 'delete', controller, target=target, class='btn btn-sm btn-primary')}}
{%- endmacro %}
